﻿using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Eneta.Portal.Common;
using Eneta.Portal.Events.Controls;

namespace Eneta.Portal.Events.WebParts
{
    [ToolboxItemAttribute(false)]
    public class EventUsersWebPart : WebPart
    {
        [WebBrowsable(true)]
        [WebDisplayName("Sündmuse ID")]
        [Category("Event WebPart settings")]
        [Personalizable(PersonalizationScope.Shared)]
        public int EventID
        {
            get;

            set;
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                var control = Page.LoadControl("~/_controltemplates/EventUsersControl.ascx") as EventUsersControl;
                if (control != null)
                {
                    if (EventID != 0)
                    {
                        control.EventID = EventID;
                        Controls.Add(control);
                    }
                    else
                    {
                        Controls.Add(new Literal() { Text = "EventID is not set" });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                Controls.Add(new Literal() { Text = ex.Message });
            }
        }
    }
}
